## usage: [J JJ] = pick_meta (mids, mvars, ids, v)
##
##
function [J JJ] = pick_meta (mids, mvars, ids, v)

   JJ = cellfun(@(x) isempty(regexp(x, "^#.*")), mids) ;

   n = length(ids) ;
   J = nan(1,n) ;

   I = find(strcmp(mvars, v)') ;
   for j = 1:n
      if ~any(wJ = strcmp(ids{j}, mids(I)))
	 warning("xds:xds", "no metadata for station %s, removing from list", ids{j}) ;
	 continue ;
      endif
      J(j) = find(wJ) ;
   endfor
   J = J(~isnan(J)) ;

   J = I(J) ;
   JJ = JJ(J) ;

endfunction
